//
//  BaiseTableViewController.swift
//  SinaWeiboDemo
//
//  Created by 伍禄林 on 16/9/20.
//  Copyright © 2016年 伍禄林. All rights reserved.
//

import UIKit

class BaiseTableViewController: UITableViewController,VisitorLoginViewDelegate {

    var isLogin = UserAccount.loadAccount() != nil
    
    var visitorLoginView: VisitorLoginView?
    
    override func loadView() {
        
        isLogin ? super.loadView() : loadVisitorView()
    
    }
    
    
    private func loadVisitorView() {
        visitorLoginView = VisitorLoginView()
        visitorLoginView?.delegate = self
        view = visitorLoginView;
        
        self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.plain, target: self, action: #selector(BaiseTableViewController.visitorWillRegister))
        
        self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登陆", style: .plain, target: self, action: #selector(BaiseTableViewController.visitorWillLogin))
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
    }

    
    func visitorWillRegister() {
        print("visitorWillRegister=======")
        
        
    }
    
    func visitorWillLogin() {
        print("visitorWillLogin=======")
        let oauthVc = OauthViewController()
        let nav = UINavigationController(rootViewController: oauthVc)
        present(nav, animated: true, completion: nil)
    }

}
